<?php

namespace app\pay\command;

use TelegramBot\Api\BotApi;
use think\cache\driver\Redis;
use think\console\Command;
use think\console\Input;
use think\console\Output;

//机器人消息阅读后自焚
class AutoClear1 extends Command
{
    protected function configure()
    {
        $this->setName('AutoClear')
            ->setDescription('阅读后自焚');
    }

    protected function execute(Input $input, Output $output)
    {
        $output->writeln('Date Crontab job start...');
        /*** 这里写计划任务列表集 START ***/
        //获取消息
        $bot = new BotApi('5466459125:AAGZI5MgYyFbZ_YufD7EmO5iObLSlRHix8M');
        $redis = new Redis();
//        $redis->set("auto_clear_1", []);
        $arr = $redis->get("auto_clear_1");
        foreach ($arr as $k => $v) {
            $end = $v['time'] + 10;
            if ($end <= time()) {
                $bot->deleteMessage($v['tid'], $v['mid']);
                unset($arr[$k]);
            }
        }
        $redis->set("auto_clear_1", $arr);
        /*** 这里写计划任务列表集 END ***/
        $output->writeln('ok');
    }

}
